package com.xbongbong.paas.factory;

import com.xbongbong.paas.constant.PaasConstant;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.FullDiscountCouponEnum;
import com.xbongbong.saas.enums.business.SpecialGoodsEnum;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 营销业务字段存储
 * @author jyh
 * @version v1.0
 * @date 2020/3/27 11:22
 * @since v1.0
 */
@Component
public class MarketingFieldHelp {

    private final static Map<Integer, Map<String, FieldAttrEntity>> MARKETING_TYPE_MAP = new ConcurrentHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);


    @PostConstruct
    public void init() {
        Map<String, FieldAttrEntity>  fullDiscountCouponEntityMap = new HashMap<>();
        for (FullDiscountCouponEnum value : FullDiscountCouponEnum.values()) {
            FieldAttrEntity entity = new FieldAttrEntity();
            entity.setAttr(value.getAttr());
            entity.setRequired(value.getRequired());
            entity.setAttrName(value.getAttrName());
            entity.setFieldType(value.getFieldType());
            fullDiscountCouponEntityMap.put(value.getAttr(), entity);
        }
        MARKETING_TYPE_MAP.put(XbbRefTypeEnum.FULL_DISCOUNT_COUPON.getCode(), fullDiscountCouponEntityMap);
        Map<String, FieldAttrEntity>  specialGoodsMap = new HashMap<>();
        for (SpecialGoodsEnum value : SpecialGoodsEnum.values()) {
            FieldAttrEntity entity = new FieldAttrEntity();
            entity.setAttr(value.getAttr());
            entity.setRequired(value.getRequired());
            entity.setAttrName(value.getAttrName());
            entity.setFieldType(value.getFieldType());
            specialGoodsMap.put(value.getAttr(), entity);
        }
        MARKETING_TYPE_MAP.put(XbbRefTypeEnum.SPECIAL_GOODS.getCode(), specialGoodsMap);
    }


    public Map<String, FieldAttrEntity> getFieldMapByBusinessType(Integer businessType) {
        return MARKETING_TYPE_MAP.get(businessType);
    }

}
